package security.dao;

import javax.annotation.Resource;
import javax.ejb.Asynchronous;
import javax.ejb.Stateless;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

@Stateless
public class MailDAO {
	
	
	@Resource(name = "mail")  
    private javax.mail.Session mailSession;  
	
	@Asynchronous
	public void send(String to, String subject, String text){
		try {	
			//mailSession.setDebug(true);
			MimeMessage message = new MimeMessage(mailSession);
			message.setFrom(new InternetAddress("noreply@asterisk365.com"));
			message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
			message.setSubject(subject);
			message.setText(text,"UTF-8","html");			
			Transport.send(message);
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	

}
